//
//  MyCarCell.swift
//  fho
//
//  Created by 郭颢源 on 2021/4/10.
//

import UIKit

class MyCarCell: UITableViewCell {
    //图片
//    var iconView = UIImageView()
    lazy var iconView:UILabel = {
        var lab = UILabel()
        lab.backgroundColor = .systemBlue
        lab.textAlignment = .center
        return lab
    }()
    
    //名称
    var nameLabel = UILabel()
    
    //分割线
    var sepView = UIView()
    var model:JSListModel = JSListModel() {
        didSet{
            //            self.iconView.image = UIImage(named: model.icon)
            self.nameLabel.text = model.title
            self.iconView.text = model.title.substring(to: 0)
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupChildViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupChildViews() {
        
        nameLabel.textAlignment = .left;
        
        sepView.backgroundColor =   UIColor(r: 200, g: 200, b: 200, a: 1)
        
        let iconWH:CGFloat = 40.0
        contentView.addSubview(iconView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(sepView)

        iconView.snp.makeConstraints { (make) in

            make.centerY.equalTo(contentView.snp.centerY)
            make.width.height.equalTo(iconWH)
            make.left.equalTo(20)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(contentView.snp.centerY)
            make.left.equalTo(iconView.snp.right).offset(20)
        }
        sepView.snp.makeConstraints { (make) in
            make.bottom.right.equalTo(0)
            make.height.equalTo(0.5)
            make.left.equalTo(nameLabel.snp.left)
        }
        
        iconView.layer.cornerRadius  = iconWH/2.0
        iconView.layer.masksToBounds = true
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
